package com.edu.ahm.thread;
/*
* 模拟网络延时 放大问题的发生性
*
* */
public class SleepTest implements Runnable {
    /*
     * sleep() 指定堵塞毫秒数
     * 时间到达后进入就绪状态
     * 每个对象都有一个锁 sleep不会释放锁
     * */

    // 票数
    private int  ticketNums =100;
    @Override
    public void run() {
        while (true){
            if (ticketNums<=0){
                break;
            }
            // 模拟网络延时
            try{
                Thread.sleep(200);
            }catch (InterruptedException e){
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"--->拿到了第"+ticketNums--+"票");
        }
    }

    public static void main(String[] args) {
        SleepTest ticket = new SleepTest();
        new Thread(ticket,"黄牛一").start();
        new Thread(ticket,"黄牛二").start();
        new Thread(ticket,"黄牛三").start();
    }




}
